﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jayden.Dll.ECMAScript
{
	public class BinaryOperator : Operator
	{
		private Expression m_LeftExpression;
		private Expression m_RightExpression;
		private string m_Sign;
		private int m_Precedence;

		public int Precedence { get { return m_Precedence; } }

		protected BinaryOperator(string sign, int precedence, Expression left, Expression right)
		{
			m_Sign = sign;
			m_Precedence = precedence;
			m_LeftExpression = left;
			m_RightExpression = right;
		}

		public void RenderExpression(StringBuilder builder)
		{
			ExpressionList.RenderOperatorExpression(this, m_LeftExpression, builder);
			builder.Append(" ");
			builder.Append(m_Sign);
			builder.Append(" ");
			ExpressionList.RenderOperatorExpression(this, m_RightExpression, builder);
		}
	}

	public class Plus : BinaryOperator
	{
		public Plus(Expression left, Expression right) : base("+", 6, left, right) { }
	}
	public class Minus : BinaryOperator
	{
		public Minus(Expression left, Expression right) : base("-", 6, left, right) { }
	}
	public class Divide : BinaryOperator
	{
		public Divide(Expression left, Expression right) : base("/", 5, left, right) { }
	}
	public class Multiply : BinaryOperator
	{
		public Multiply(Expression left, Expression right) : base("*", 5, left, right) { }
	}
	public class Modulo : BinaryOperator
	{
		public Modulo(Expression left, Expression right) : base("%", 5, left, right) { }
	}
	public class And : BinaryOperator
	{
		public And(Expression left, Expression right) : base("&&", 5, left, right) { }
	}
	public class Or : BinaryOperator
	{
		public Or(Expression left, Expression right) : base("||", 5, left, right) { }
	}
	public class Assignment : BinaryOperator
	{
		public Assignment(Expression left, Expression right) : base("=", 15, left, right) { }
	}
}
